﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>视频课程</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="../../static/css/font.css" rel="stylesheet" />
    <link href="../../static/css/weadmin.css" rel="stylesheet" />
    <link href="../../lib/layui/css/layui.css" rel="stylesheet" />
    <script src="../../../lib/layui/layui.js"></script>
</head>
<body>
    <div class="weadmin-nav">
        <span class="layui-breadcrumb" style="visibility: visible;">
            <a href="#">首页</a><span lay-separator="">/</span>
            <a href="#">查询统计</a><span lay-separator="">/</span>
            <a><cite>课程视频</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="layui-fluid fluid-position">
        <div class="layui-inline">
            <div class="layui-inline">
                <label class="layui-form-label">起止时间</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="StartDateTime" />
                </div>
                <div class="layui-input-inline layui-form-label-inner">
                    <input type="text" class="layui-input" id="EndDateTime" name="EndDateTime" />
                </div>
            </div>
            <div class="layui-input-inline">
                <input type="text" placeholder="计划名称" maxlength="50" class="layui-input" id="PlanName" name="PlanName" />
            </div>
            <div class="layui-input-inline">
                <input type="text" placeholder="视频名称" maxlength="50" class="layui-input" id="VideoName" name="VideoName" />
            </div>
            <div class="layui-input-inline">
                <input type="text" placeholder="课程名称" maxlength="50" class="layui-input" id="CourseName" name="CourseName" />
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn layui-btn-primary" id="find" name="查询"><i class="layui-icon">&#xe615;</i>查询</button>
                    <button type="button" class="layui-btn layui-btn-primary" id="reset" name="清空"><i class="layui-icon">&#xe669;</i>清空</button>
                </div>
            </div>
        </div>

    </div>
    <div class="layui-fluid" id="infos">
    </div>
    <div style="width:50%;" class="lay-row">
        <button type="button" class="layui-btn layui-btn-normal" id="pre">上一页</button>
        <button type="button" class="layui-btn layui-btn-normal" id="next">下一页</button>
    </div>

    <script>
        var ModleNameTip = "培训课程";  //模块名称  用于提示部门信息的内容
        var contollerName = "TrainCourse";
        var cheduiList = [];
        var load = 1;
        var limit = 12;
        var page = 1;
        var CPID = 0;//所属集团计划id  带过来的 或者直接选过来的
        var refTPID = 0;//携带过来的计划id
        var prePlanId = 0;//选择的上级培训计划id
        var selectIDs = [];//选中的id列表 [可用批量删除  审核 取消 ]
        var selectCurrentID = 0;// 当前选中的 id  [用于修改]
        var currentDeptLevelId = 0;//当前登录者 部门级别  0：是段
        var currentInfoDeptLevelId = 0;//当前选中信息的  部门级别  [用于判断 是否能够对 该条信息进行修改:下级不能对上级的计划信息进行修改]
        var cuurentDeptId = 0;//当前部门id
        var img = ApiUrl.replace("api", "");
        var selectCurrentIsCheckStatus = 0;// 当前选中的行的 IsChck 状态  [用于删除/审核/取消审核/发布/取消发布时判断]
        var selectCurrentIsReleaseStatus = 0;// 当前选中的行的 IsRelease 状态  [用于删除/审核/取消审核/发布/取消发布时判断]

        var currentInfoDeptId = 0;//当前选中信息的 部门id
        var selectobjs = [];//
        var CurrentSelectCRID = 0;//当前选择信息的教室id
        var FileListIds = [];//选择的文件资料id 列表
        var currentTCOName = "";
        var teacherList = [];//教师列表
        var classRoom = [];//教室列表
        //加载 [赋值]获取数据  (部门相关数据)
        var dataSelect = [];
        var temp_deptId_List = [];//列表中选择信息时   使用字段中的内容=>为其赋值,可以使用此字段保存
        var dataCurent = [];
        var th = 0;
        var tw = 0;
        //选择上级计划/集团计划 【段筛选 集团计划， 下级都筛选培训计划  根据当前部门级别来判断， 段是0】

        function updateVedio(v1, v2) {
            layui.use(['layer', 'jquery'], function () {
                var h = th * 1.8;
                var w = tw * 0.7;
                var layer = layui.layer;
                var $ = layui.jquery;
                var contentPage = "VedioUpdate.html?AutoID=" + v1 + "&VideoName=" + v2 + "";
                var title = v2;
                layer.open({
                    title: title,
                    type: 2,
                    area: ["600px", "200px"],
                    content: contentPage,
                    btn: ['确定', '关闭'],
                    yes: function (index) {
                        var res = window["layui-layer-iframe" + index].selectdata();
                        if (res.AutoID != 0) {
                            if (res.VideoName == "") { layer.msg("视频名称不能为空!"); return; }
                            if (res.VideoName == v2) { layer.close(index); return; }
                            var v = {
                                AutoID: res.AutoID,
                                VideoName: res.VideoName
                            };
                            $.ajax({
                                url: ApiUrl + "CameraVideo/Edit",
                                type: 'post',
                                dataType: 'json',
                                cache: false,
                                data: v,
                                headers: {
                                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                                },
                                success: function (data) {
                                    if (data.StatusCode == 200) {
                                        layer.alert("添加保存成功", { icon: 6 }, function (index) {
                                            $("#" + res.AutoID).html(res.VideoName);
                                            $("button[value=" + res.AutoID + "]").attr("tag", res.VideoName);
                                            layer.close(index);
                                        })
                                    }
                                    else if (data.StatusCode == 403) {
                                        top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                            v.AutoID = 0;
                                            top.location.href = "http://" + top.location.host + "/login.html";
                                        })
                                    }
                                    else {
                                        v.AutoID = 0;
                                        layer.msg(data.Data);
                                    }
                                }
                            });
                        }
                        layer.close(index);
                    }
                });
            });
        };
        layui.use(['form', 'laydate', 'table', 'jquery', 'element', 'layer', 'tree', 'util'], function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            th = $(document).height() * 0.5;
            tw = $(document).width();
            var table = layui.table;
            var form = layui.form;
            var element = layui.element;
            var layer = layui.layer;
            var eleTree = layui.tree;
            $(".layui-card-header").find("button").each(function () { if (PowerList.indexOf($(this).attr("name")) <= -1) { $(this).attr("style", "display:none;") } });
            form.on('switch(switch)', function (data) { });
            laydate.render({ elem: '#StartDateTime', trigger: 'click', format: 'yyyy-MM-dd' });
            laydate.render({ elem: '#EndDateTime', trigger: 'click', format: 'yyyy-MM-dd' });
            function formRenderSelect() {
                form.render('select');
            }
            function InitItem() {
                $("button[name='play']").off("click").on("click", function () { VedioPlay($(this).attr("value"), $(this).attr("tag")); }); $("button[name='set']").off("click").on("click", function () { updateVedio($(this).attr("value"), $(this).attr("tag")); });
            }
            function CreateVedio(objs) {
                var c = "";
                $("#infos").empty();
                for (var i = 0; i < objs.length; i++) {
                    var item = objs[i];
                    c += "<div class=\"fluids\">";
                    c += "<div class=\"fluids-ibox layui-col\">";
                    c += " <div><img src=\"" + img + item.VideoStartImg + "\" /></div>";
                    c += "</div>";
                    c += "<div id=\"" + item.AutoID + "\">" + item.VideoName + "</div>";
                    c += "<button style=\"margin-rigth:10px\" type=\"button\" class=\"layui-btn layui-btn-primary\" name=\"set\" value=\"" + item.AutoID + "\" tag=\"" + item.VideoName + "\">设置</button>";
                    c += "<button type=\"button\" class=\"layui-btn layui-btn-primary\" name=\"play\" value=\"" + img + item.VideoAddress + "\" tag=\"" + item.VideoName + "\">播放</button>";
                    c += "<a class=\"layui-btn fluids-btn layui-btn-primary\" name=\"play\" href=\"" + img + item.VideoAddress + "\"  download=\"" + item.VideoName + "\" >下载</a>";
                    c += "</div>";
                    c += "</div>";

                }
                $("#infos").append(c); InitItem();
            }

            function GetChedui() {
                $.ajax({
                    url: ApiUrl + "TrainCourse/GetCheduiList",
                    type: 'get',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            if (cheduiList.length <= 0) {
                                for (var f = 0; f < data.Data.length; f++) {
                                    var item = data.Data[f];
                                    cheduiList.push(item.DepID);
                                }
                            }
                            ShowList(2);
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }

            function ShowList(type) {
                var swhere = JSON.stringify({
                    cheduiList: cheduiList.toString(),
                    PlanName: $("#PlanName").val(),
                    VideoName: $("#VideoName").val(),
                    CourseName: $("#CourseName").val(),
                    StartDateTime: $("#StartDateTime").val(),
                    EndDateTime: $("#EndDateTime").val()
                });
                $.ajax({
                    url: ApiUrl + "CameraVideo/Search?swhere=" + swhere + "&page=" + page + "&limit=" + limit + "",
                    type: 'get',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            if (data.Data != null) {
                                CreateVedio(data.Data);
                            }
                            else {
                                if (type < 2) { layer.msg("已是最后一页了"); page--; return; } else { $("#infos").empty(); }
                            }
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
            GetChedui();
            $("#next").click(function () {
                page++;
                ShowList(0);
            });
            $("#pre").click(function () {
                page--;
                if (page < 1) {
                    page = 1;
                }
                ShowList(1);
            });
            function clearForm() {
                $("textarea").val("");
                $("input").val("");
            }
            function VedioPlay(v, vedio) {

                var sign = 0; //弹出视频窗体标志
                //alert("浏览器:" + getExplorerInfo().type + "\n 版本:" + getExplorerInfo().version);
                var ExplorerType = getExplorerInfo().type; //浏览器
                var ExplorerVersion = getExplorerInfo().version; //浏览器版本

                if (ExplorerType == 'Firefox') {
                    var version = ExplorerVersion.substr(0, 2);
                    if (version < 70) {
                        alert("你的火狐浏览器版本过低，请下载提供的火狐浏览器！")
                        window.location.href = DownUrl + "uploads/Firefox_70.exe";
                    }
                    else {
                        sign = 1;
                    }
                }
                else {
                    sign = 1;
                }

                if (sign == 1) {
                    var h = th * 1.9;
                    var w = tw * 0.9;
                    layer.open({
                        type: 1,
                        shadeClose: true,
                        shade: 0.3,
                        title: vedio,
                        area: [w + "px", h + "px"],
                        content: play(v),
                    });
                }

            }
            $("#find").click(function () {
                if (cheduiList.length > 0) {
                    ShowList(2);
                }
                else {
                    GetChedui();
                }
            });
            $("#reset").click(function () {
                clearForm();
                temp_deptId_List = [];
                selectCurrentID = 0;
            });
            //校验数据
            function CheckData() {
                if (prePlanId <= 0) {
                    layer.msg("请选择授课内容！");
                    return false;
                }
                if ($("#StartDateTime").val().trim() == "") {
                    layer.msg("请选择开始时间！");
                    return false;
                }
                if ($("#EndDateTime").val().trim() == "") {
                    layer.msg("请选择结束时间！");
                    return false;
                }
                if ($("#Duration").val().trim() == "") {
                    layer.msg("请输入时长(分钟)！");
                    return false;
                }
                return true;
            }
        });
        function getExplorerInfo() {
            var explorer = window.navigator.userAgent.toLowerCase();
            //ie
            if (explorer.indexOf("msie") >= 0) {
                var ver = explorer.match(/msie ([\d.]+)/)[1];
                return { type: "IE", version: ver };
            }
            //firefox
            else if (explorer.indexOf("firefox") >= 0) {
                var ver = explorer.match(/firefox\/([\d.]+)/)[1];
                return { type: "Firefox", version: ver };
            }
            //Chrome
            else if (explorer.indexOf("chrome") >= 0) {
                var ver = explorer.match(/chrome\/([\d.]+)/)[1];
                return { type: "Chrome", version: ver };
            }
            //Opera
            else if (explorer.indexOf("opera") >= 0) {
                var ver = explorer.match(/opera.([\d.]+)/)[1];
                return { type: "Opera", version: ver };
            }
            //Safari
            else if (explorer.indexOf("Safari") >= 0) {
                var ver = explorer.match(/version\/([\d.]+)/)[1];
                return { type: "Safari", version: ver };
            }
        }
    </script>
</body>
</html>